<?php

namespace App\Jobs;

use App\Helpers\NewBaseData;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Modules\Car\Entities\CarOrder;

class CloseOrder implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels,NewBaseData;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    protected $order;
    public function __construct()
    {
        //
       // $this->order = $order;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        // info('开始执行订单定时关闭');
        $order = CarOrder::query()
            ->where('status',0)
            ->where('created_at','<',now()->subMinutes(20))
            ->get();
        if($order){
            foreach ($order as $item){
                if($item->status==0){
                    $item->status = -3;
                    if($item->is_coupon==1){
                        $this->recoupon($item->coupon_id);
                    }
                }
                $item->save();
            }
        }
    }

}
